package com.alibaba.csp.sentinel.dashboard.rule.nacos;

import com.alibaba.csp.sentinel.dashboard.rule.DynamicRulePublisher;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;

import javax.annotation.Resource;
import java.util.List;

/**
 * 通用创建规则
 * @author chengjian 
 * @date 2021/7/7
 */
public abstract class AbstractDynamicPublisher<M> implements DynamicRulePublisher<M> {
    @Resource
    private ConfigService configService;

    public void publishByDataId(String app, List<M> rules) throws NacosException {
        NacosConfigUtil.setRuleStringToNacos(configService, app, ruleName(), rules);
    }

    /**
     * 规则后缀名称
     * @author chengjian
     * @date 2021/7/7 5:14 下午
     * @return String
     */
    public abstract String ruleName();
}
